# Base images 基础镜像
FROM centos:7

# MAINTAINER 维护者信息
# MAINTAINER tangmingrui
# LABEL maintainer tangmingrui@qq.com


# GCC编译器
RUN yum install gcc -y


# python依赖
RUN yum install -y zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel openssl openssl-devel

# wget
RUN yum install wget -y

# 目录
RUN mkdir -p /data/
WORKDIR /data/

# SQLite升级
RUN wget https://www.sqlite.org/2023/sqlite-autoconf-3420000.tar.gz --no-check-certificate
RUN tar -zxvf sqlite-autoconf-3420000.tar.gz
WORKDIR /data/sqlite-autoconf-3420000
RUN ./configure
RUN make && make install
ENV LD_LIBRARY_PATH="/usr/local/lib"

# python3.8环境
WORKDIR /data/
# WORKDIR /root/django-docker/
#RUN wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.taz
# ADD https://mirrors.huaweicloud.com/python/3.8.5/Python-3.8.5.tgz .
# 国内pytho源：https://mirrors.huaweicloud.com/python/3.8.5/Python-3.8.5.tgz
# 复制宿主机python-3.8.5.tgz到容器中，该文件在Dockerfile同目录文件夹中，才能复制到容器WORKDIR /data/
COPY Python-3.8.0.tgz .
# 上传依赖包
COPY requirements.txt .
RUN tar -xvf Python-3.8.0.tgz
WORKDIR /data/Python-3.8.0/
RUN ./configure
RUN make && make install
# 更换国内源
RUN pip3.8 config set global.index-url https://pypi.douban.com/simple/

# git
RUN yum install git -y
RUN git config --global user.name "tang"
RUN git config --global user.email "1171242903@qq.com"

# git拉代码
WORKDIR /data/
RUN git clone https://gitee.com/i-lay-in-my-hole/django_init_project.git


# 虚拟环境
RUN pip3.8 install virtualenv
RUN virtualenv /envs/dj --python=python3.8
RUN /envs/dj/bin/pip3.8 install -i https://pypi.douban.com/simple/ -r requirements.txt
# RUN /envs/dj/bin/pip3.8 install -i https://pypi.douban.com/simple/ channels==3.0.2

# 运行项目
WORKDIR /data/django_init_project
CMD ["/envs/dj/bin/python", "manage.py", "migrate"]
CMD ["/envs/dj/bin/python", "manage.py", "runserver", "0.0.0.0:9000"]